package com.weiyi.mashangzhu.Roomer.Activity;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.squareup.okhttp.Request;
import com.weiyi.mashangzhu.API.API;
import com.weiyi.mashangzhu.Base.BaseActivity;
import com.weiyi.mashangzhu.R;
import com.weiyi.mashangzhu.Roomer.Bean.HelpBean;
import com.weiyi.mashangzhu.Utils.LoadingDialog;
import com.weiyi.mashangzhu.Utils.SPUtils;
import com.weiyi.mashangzhu.Utils.T;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class HelpActivity extends BaseActivity {

    @BindView(R.id.layout)
    LinearLayout layout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_help);
        ButterKnife.bind(this);
        initView();
    }

    @Override
    public void initView() {
        super.initView();
        LoadingDialog.show(this);
        OkHttpUtils.get().addParams("token", SPUtils.get(this, "token", "") + "").url(API.BaseApi_R + API.Help_Api).build().execute(new StringCallback() {
            @Override
            public void onError(Request request, Exception e) {
                LoadingDialog.dismiss(HelpActivity.this);
                T.showShort(HelpActivity.this, "网络连接失败，请检查一下网络设置");
            }

            @Override
            public void onResponse(String response) {
                LoadingDialog.dismiss(HelpActivity.this);
                Gson gson = new Gson();
                HelpBean helpBean = gson.fromJson(response, HelpBean.class);
                for (int i = 0; i < helpBean.getData().size(); i++) {
                    View view = LayoutInflater.from(HelpActivity.this).inflate(R.layout.item_help, null);
                    TextView q = (TextView) view.findViewById(R.id.help_question);
                    TextView c = (TextView) view.findViewById(R.id.help_content);
                    q.setText((i+1)+". "+helpBean.getData().get(i).getFeedDesc() + "");
                    c.setText(helpBean.getData().get(i).getFeedAnswer()+"");
                    layout.addView(view);
                }

            }
        });

    }

    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }
}
